package com.problemproject.dome.viewpager;

import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.List;

/**
 * 创建时间 : 2022/4/2
 * 描述：
 */

public class ViewPageAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragments;
    private String title [];
    public ViewPageAdapter(@NonNull  FragmentManager fm, List<Fragment> fragments,String title[]) {
        super(fm);
        this.fragments = fragments;
        this.title=title;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return title[position];
    }

    @Override
    public void destroyItem(@NonNull  ViewGroup container, int position, @NonNull  Object object) {
        //(1) FragmentPagerAdapter 中重写父类的destroyItem 方法.
        //(2) 在destroyItem方法中,删除 super()的父类实现方法.
    }
}
